/*
 * Copyright (C) 2019-2020 FoilPlanet
 *
 */

#ifndef ANBOX_PLATFORM_GBM_PLATFORM_H_
#define ANBOX_PLATFORM_GBM_PLATFORM_H_

#include "anbox/platform/base_platform.h"

#include <map>
class Renderer;

namespace anbox {
namespace platform {
namespace gbm {

class Platform : public BasePlatform {
  public:
    Platform(const std::shared_ptr<input::Manager> &input_manager,
            const graphics::Rect &static_display_frame = graphics::Rect::Invalid,
            bool single_window = false);

    std::shared_ptr<wm::Window>
    create_window(const anbox::wm::Task::Id &task,
                  const anbox::graphics::Rect &frame,
                  const std::string &title) override;

    void set_clipboard_data(const ClipboardData &data) override;
    ClipboardData get_clipboard_data() override;
    std::shared_ptr<audio::Sink> create_audio_sink() override;
    std::shared_ptr<audio::Source> create_audio_source() override;

    void set_renderer(const std::shared_ptr<Renderer> &renderer) override {
      renderer_ = renderer;
    }

    void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) override {
      window_manager_ = window_manager;
    }

    bool supports_multi_window() const override {
      return true;
    }

    /**
     * Get native display (GBM device)
     */
    void *get_display() override;

  private:

    static uint32_t next_window_id();

    std::map<uint32_t, std::weak_ptr<wm::Window>> windows_;

    std::shared_ptr<Renderer>       renderer_;
    std::shared_ptr<input::Manager> input_manager_;
    std::shared_ptr<wm::Manager>    window_manager_;
    graphics::Rect                  display_frame_;
    std::shared_ptr<wm::Window>     current_window_;
    bool single_window_ = false;
};

}  // namespace gbm
}  // namespace wm
}  // namespace anbox

#endif /* ANBOX_PLATFORM_GBM_PLATFORM_H_ */